﻿using Microsoft.AspNetCore.Http;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using UtilsCache;
using UtilsORM;
using UtilsORM.MySqlData;

////using System.Web.Script.Serialization;

namespace GatewayServerService.Data
{
    public class DBIotDeviceCommandCache
    {



        //public List<iot_device_command> getCommandListByCache()
        //{
        //    List<iot_device_command> list = UtilMemoryCacheHelper.StringGet<List<iot_device_command>>("deviceCommandlist");//数据太多，报错
        //    if (list == null)
        //    {
        //        list = ef.iot_device_command.Where(c => c.dc_status == 0).ToList();
        //        UtilMemoryCacheHelper.StringSet("deviceCommandlist", list, 30);
        //    }
        //    return list;
        //}

        public iot_device_command getCommandByCache(string modelGuid, string key)
        {
            EFYihongIotContext ef = new EFYihongIotContext();
            iot_device_command command = UtilMemoryCacheHelper.StringGet<iot_device_command>("getCommandByCache_" + modelGuid + key);//数据太多，报错
            if (command == null)
            {
                command = ef.iot_device_command.Where(c => c.dc_model_guid == modelGuid && c.dc_key == key && c.dc_status == 0).FirstOrDefault();
                UtilMemoryCacheHelper.StringSet("getCommandByCache_" + modelGuid + key, command, 1);
            }
            return command;
        }
    }
}
